﻿using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace CoreWeb
{
    public class ExceptionLogFilterAttribute : ExceptionFilterAttribute
    {
        readonly ILoggerFactory _factory;

        public ExceptionLogFilterAttribute(ILoggerFactory factory)
        {
            _factory = factory;
        }
        public override void OnException(ExceptionContext context)
        {
            var logger = _factory.CreateLogger(context.RouteData.Values["controller"] + "." + context.RouteData.Values["action"]);
            logger.LogError(context.Exception, context.Exception.Message);
        }
    }
}
